package cn.cloud.jianghai.orderservice.controller;

import cn.cloud.jianghai.jianghaicommon.entity.R;
import cn.cloud.jianghai.orderapi.entity.OrderDto;
import cn.cloud.jianghai.orderservice.query.OrderQuery;
import cn.cloud.jianghai.orderservice.service.OrderService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Jiang.h
 * created 2022/5/21 18:47
 */
@RestController
@RequestMapping("/v1/order/")
@RequiredArgsConstructor
public class OrderController {


    private final OrderService orderService;

    /**
     * 查询订单列表
     * @param orderQuery 查询参数
     * @Date 2022/5/22 12:30
     * @Author Jiang.h
     * @return void
     **/
    @GetMapping("/findOrderList")
    public R<List<OrderDto>> findOrderList(OrderQuery orderQuery) {

        return R.success(orderService.findOrderList(orderQuery));
    }

    @GetMapping("/findByPage")
    public R<Page<OrderDto>> findByPage(OrderQuery query) {

        return R.success(orderService.findByPage(query));
    }


    /**
     *  新增订单
     * @param orderDto 订单数据
     * @Date 2022/5/22 13:02
     * @Author Jiang.h
     * @return cn.cloud.jianghai.orderapi.entity.R<java.lang.Boolean>
     **/
    @PostMapping("/insert")
    public R<Boolean> insert(@RequestBody OrderDto orderDto) {
        return R.success(orderService.insert(orderDto));
    }

    /**
     * 删除
     * @param id 主键
     * @Date 2022/5/22 13:24
     * @Author Jiang.h
     * @return cn.cloud.jianghai.orderapi.entity.R<java.lang.Boolean>
     **/
    @DeleteMapping("/del/{id}")
    public R<Boolean> del(@PathVariable("id") Long id) {

        return R.success(orderService.del(id));
    }

    /**
     * 更新
     * @param orderDto 数据
     * @Date 2022/5/22 13:26
     * @Author Jiang.h
     * @return cn.cloud.jianghai.orderapi.entity.R<java.lang.Boolean>
     **/
    @PutMapping("/edit")
    public R<Boolean> edit(@RequestBody OrderDto orderDto) {

        return R.success(orderService.edit(orderDto));
    }

    /**
     * 根据id查询
     * @param id id
     * @Date 2022/6/1 13:48
     * @Author Jiang.h
     * @return cn.cloud.jianghai.jianghaicommon.entity.R<cn.cloud.jianghai.orderapi.entity.OrderDto>
     **/
    @GetMapping("/getById/{id}")
    public R<OrderDto> getById(@PathVariable("id") Long id) {
        return R.success(orderService.get(id));
    }
}
